package com.dgut.service.impl;

import com.dgut.dao.UserDao;
import com.dgut.domain.User;
import com.dgut.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;

    @Override

    public List<User> findAllUser() {
        return userDao.findAllUser();
    }

    @Override
    public Integer findUser(User user) {
        return userDao.findUser(user);
    }

    public List<Integer> getUserIdLIst(){
        List<Integer> ids = new ArrayList<>();
        List<User> users = userDao.findAllUser();
        for (User user:users) {
            ids.add(user.getId());
        }
        return ids;

    }
//    测试
    public List<User> getUserCustomer(){
        return userDao.findAllUser();
    }
    public User findUserById(int id){
        return userDao.findUserById(id);
    }

    @Override
    public User findUserByName(String name) {
        return userDao.findUserByName(name);
    }

    @Override
    public void insertUser(String name, String password) {
        userDao.insertUser(name,password);
    }

    @Override
    public boolean ifNameExit(String name) {
        if(userDao.findUserByName(name) != null){
            return true;
        }else {
            return false;
        }

    }

    @Override
    public void updateUser(User user) {
        userDao.updateUser(user);
    }
}
